package cn.iocoder.yudao.module.famous.doctor.controller.app.reply;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import cn.iocoder.yudao.module.famous.doctor.controller.admin.reply.vo.*;
import cn.iocoder.yudao.module.famous.doctor.convert.reply.FamReplyConvert;
import cn.iocoder.yudao.module.famous.doctor.dal.dataobject.reply.FamReplyDO;
import cn.iocoder.yudao.module.famous.doctor.service.reply.FamReplyService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.util.Collection;
import java.util.List;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;

@Tag(name = "用户 APP - 谈论回复")
@RestController
@RequestMapping("/famous.doctor/fam-reply/app")
@Validated
public class AppFamReplyController {

    @Resource
    private FamReplyService famReplyService;

    @PostMapping("/create")
    @Operation(summary = "创建谈论回复")
    public CommonResult<Long> createFamReply(@Valid @RequestBody FamReplyCreateReqVO createReqVO) {
        return success(famReplyService.createFamReply(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新谈论回复")
    public CommonResult<Boolean> updateFamReply(@Valid @RequestBody FamReplyUpdateReqVO updateReqVO) {
        famReplyService.updateFamReply(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除谈论回复")
    @Parameter(name = "id", description = "编号", required = true)
    public CommonResult<Boolean> deleteFamReply(@RequestParam("id") Long id) {
        famReplyService.deleteFamReply(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得谈论回复")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<FamReplyRespVO> getFamReply(@RequestParam("id") Long id) {
        FamReplyDO famReply = famReplyService.getFamReply(id);
        return success(FamReplyConvert.INSTANCE.convert(famReply));
    }

    @GetMapping("/list")
    @Operation(summary = "获得谈论回复列表")
    @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
    public CommonResult<List<FamReplyRespVO>> getFamReplyList(@RequestParam("ids") Collection<Long> ids) {
        List<FamReplyDO> list = famReplyService.getFamReplyList(ids);
        return success(FamReplyConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/page")
    @Operation(summary = "获得谈论回复分页")
    public CommonResult<PageResult<FamReplyRespVO>> getFamReplyPage(@Valid FamReplyPageReqVO pageVO) {
    PageResult<FamReplyDO> pageResult = famReplyService.getFamReplyPage(pageVO);
        return success(FamReplyConvert.INSTANCE.convertPage(pageResult));
}

    @GetMapping("/pageParticulars")
    @Operation(summary = "获得谈论回复详情分页")
    public CommonResult<IPage<FamReplyRespTwoVO>> getFamReplyPageParticulars(@Valid FamReplyPageTwoReqVO pageVO) {
        pageVO.setLoginUser(getLoginUserId());
        IPage<FamReplyRespTwoVO> pageResult = famReplyService.getFamReplyPageParticulars(pageVO);
        return success(pageResult);
    }

}
